package com.example.test.netty;

import com.example.test.netty.decode.MessageDecoder;
import com.example.test.netty.encode.MessageEncoder;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;

/**
 * @program: test
 * @description: BootNettyChannelInitializer 通道初始化
 * @author: qiu bo yang
 * @create: 2020-10-13 11:07
 **/
public class BootNettyChannelInitializer<SocketChannel> extends ChannelInitializer<Channel> {
    @Override
    protected void initChannel(Channel channel) throws Exception {
        //channel.pipeline().addLast("framedecoder",new LengthFieldBasedFrameDecoder(20*1024,0,2));
        //自定义解码器
        channel.pipeline().addLast("decoder", new MessageDecoder());
        //自定义编码器
        channel.pipeline().addLast("encoder",new MessageEncoder());
        //自定义ChannelInboundHandlerAdapter
        channel.pipeline().addLast(new BootNettyChannelInboundHandlerAdapter());
    }
}
